'use strict';

angular.module('App').controller('AppListController', ['$scope', 'BaseFunction', 'BaseModule', 'BaseEnum', '$location', 'Authentication',
    function($scope, BaseFunction, BaseModule, BaseEnum, $location, Authentication) {
    	$scope.DeviceTypeEnum = BaseFunction.getEnum('AppEnum.DeviceType');

    	BaseModule.initModule($scope, 'App');
        $scope.Module.App.LoadMode = BaseEnum.LoadMode.CacheAndPaging;
        $scope.Module.App.PageSize = 15;
        $scope.Module.App.OrderBy = {Name: 1, Code: 1};
        $scope.Module.App.AfterOnLoad = function(records){
            for(var i=0; i<records.length; i++){
                if(records[i].DisplayImage != undefined && records[i].DisplayImage != null && records[i].DisplayImage.trim().length > 0){
                    records[i].IsImg = true;
                }
                if(records[i].MouseDownImage != undefined && records[i].MouseDownImage != null && records[i].MouseDownImage.trim().length > 0){
                    records[i].IsDownImg = true;
                }
            }
        };

        $scope.btnAdd = function(){
        	$location.url('/index/App/Edit');
        };

        $scope.rowDblClick = function(){
            $scope.$apply(function(){
                $location.url("/index/App/Edit/" + $scope.Module.App.FocusedRecord._id);
            });
        };

        $scope.btnDelete = function(){
        	$scope.Module.App.deleteSelecteds();
        };
    }
]);
